package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 插入菜品数据
     *
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);
    /*
     * @description:菜品的分页查询
     * @author: song
     * @date: 2024/1/2 14:19
     * @param: [dishPageQueryDTO]
     * @return: com.github.pagehelper.Page<com.sky.vo.DishVO>
     **/
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);
    /*
     * @description:根据id查询菜品
     * @author: song
     * @date: 2024/1/2 14:19
     * @param: [id]
     * @return: com.sky.entity.Dish
     **/
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);
    /*
     * @description:根据id删除菜品
     * @author: song
     * @date: 2024/1/2 14:19
     * @param: [id]
     * @return: void
     **/
    @Delete("delete  from dish where id= #{id}")
    void deleteById(Long id);
    /*
     * @description:修改菜品信息
     * @author: song
     * @date: 2024/1/2 14:18
     * @param: [dish]
     * @return: void
     **/
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);
    /*
     * @description:根据动态条件查询
     * @author: song
     * @date: 2024/1/2 14:19
     * @param: [dish]
     * @return: java.util.List<com.sky.entity.Dish>
     **/
    List<Dish> list(Dish dish);
    @Select("select a.* from dish a left join setmeal_dish b " +
            "on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long id);
}
